package com.dailyblue.example.springcloud.seata.stock.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dailyblue.example.springcloud.commons.util.JsonResult;
import com.dailyblue.example.springcloud.commons.util.ResultTool;
import com.dailyblue.example.springcloud.seata.stock.bean.Stock;
import com.dailyblue.example.springcloud.seata.stock.mapper.StockMapper;
import com.dailyblue.example.springcloud.seata.stock.service.StockService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;

import java.sql.SQLException;

@Service
public class StockServiceImpl extends ServiceImpl<StockMapper, Stock> implements StockService {

    @GlobalTransactional
    @SneakyThrows
    public JsonResult updateStock(String id, int number) {
        int row = getBaseMapper().update(id, number);
        if (row == 0) {
            throw new SQLException();
        }
        return ResultTool.success("success");
    }
}
